package leetcode.code116.PopulatingNextRightPointersinEachNode;

import leetcode.helper.tree.Node;

public class Solution11601 extends PopulatingNextRightPointersinEachNode {

	@Override
	public Node connect(Node root) {
		if ((root == null) || (root.left == null))
			return root;
		root.left.next = root.right;
		if (root.next != null)
			root.right.next = root.next.left;
		else
			root.right.next = null;
		connect(root.left);
		connect(root.right);
		return root;
	}

	public static void main(String[] args) {
		Solution11601 so = new Solution11601();
		so.debug1();
		so.debug2();
	}

}
